<?php require("inc/common.inc.php");
ob_start();
$id=intval($id);
if($type == 'nowbuy'){
	if(empty($_COOKIE['userid']) || $_COOKIE['userid']=="" || empty($_COOKIE['username']) || $_COOKIE['username']==""){
		$return["success"]=false;
		$return['msg'] = "您需要登录后才可以操作。";
		echo json_encode($return);
		exit();
	}else{
		$mxuserid = $_COOKIE['userid'];
		$mxusername = $_COOKIE['username'];
		$mxnickname = $_COOKIE['nickname'];
	
	}
	$return="";
	if(!$id){
		$return["success"]=false;
		$return["msg"]="非法访问";
		echo json_encode($return);
		exit();
	}
	
	if(!$count){
		$return["success"]=false;
		$return["msg"]="数量最小为1";
		echo json_encode($return);
		exit();
	}
	
	$productInfo = $db->getinfo("select * from mx_vpp_article where aid=$id");
	$allprice = $productInfo['vipprice']*$count;
	
	$mxuserInfo = $db->getinfo("select * from mx_app_user where id=$mxuserid");
	if($allprice > $mxuserInfo['money']){
		$return["success"]=false;
		$return["msg"]="您的余额不足，请到店内充值后继续";
		echo json_encode($return);
		exit();
	}
	$integral = floor($allprice/20);
	$intro = "购买".$productInfo['title'].'x'.$count;
	$files=array(
			"userid"=>$mxuserid,
			"number"    =>$allprice,
			"type"      =>2,
			"intro"    =>$intro,
			"createtime"  =>time(),
	);
	$db->exe_insert("mx_app_user_money",$files);
	$goods_files=array(
			"userid"=>$mxuserid,
			"goodsid"    =>$id,
			"intro"    =>$intro,
			"adddate"  =>date('Y-m-d H:i:s')
	);
	$db->exe_insert("mx_app_user_goods_log",$goods_files);
	$db->exe_update('mx_app_user', array('money'=>$mxuserInfo['money']-$allprice),"id=".$mxuserid);
	addIntegral($integral, $mxuserid,$intro);
	$targetuserid = $_COOKIE['share_targetuserid'];
	if($targetuserid){
		$newIntegral = $integral/2;
		$intro = "通过分享，".$mxuserInfo['realname'].$intro;
		giveIntegral($targetuserid, $newIntegral, $intro,2);
	}
	$return["success"]=true;
	$return["msg"]="购买成功，赠送您".$integral."积分！";
	echo json_encode($return);
	exit();
}elseif($type == 'cart'){
	if(empty($_COOKIE['userid']) || $_COOKIE['userid']=="" || empty($_COOKIE['username']) || $_COOKIE['username']==""){
		$return["success"]=false;
		$return['msg'] = "您需要登录后才可以操作。";
		echo json_encode($return);
		exit();
	}else{
		$mxuserid = $_COOKIE['userid'];
		$mxusername = $_COOKIE['username'];
		$mxnickname = $_COOKIE['nickname'];
	
	}
	$return="";
	if(!$id){
		$return["success"]=false;
		$return["msg"]="非法访问";
		echo json_encode($return);
		exit();
	}
	
	if(!$count){
		$return["success"]=false;
		$return["msg"]="数量最小为1";
		echo json_encode($return);
		exit();
	}
	
	require("inc/cart.php");
	$cart = new Cart();
	$goods = array('id' => $id,'num' => $count,'price' => $price,'name' => $name,'picurl'=>$picurl,'aid'=>$aid);
	$cart->insert($goods);
	$return["success"]=true;
	$return['msg'] = "加入购物车成功";
	echo json_encode($return);
	exit();
}?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1" name="viewport">
<?php 
if($id==""){
    $fun->popmassage("非法操作，系统将自动返回上一页!","","popback");
    exit();
}
  $sqlsel="select *  from mx_vpp_article where aid='$id' and yz='1'";
  $rs=$db->excu($sqlsel);
  if ($db->num_rows($rs)<=0){
    $fun->popmassage("非法操作，系统将自动返回上一页!","","popback");
    exit();
  }
  $newsdb=$db->fetch_array($rs);
  if ($newsdb["iframeurl"]==1){
	  echo "<meta http-equiv=\"refresh\" content=\"0;URL=$newsdb[jumpurl]\">";
	  exit();
  }
  $db->excu("update mx_vpp_article set hits=hits+1 where aid=$id");
  $article_title="$newsdb[title]";
  $article_title2="$newsdb[title] ";

 
  $sqlsel="select *  from mx_vpp_articleclass where fid='$newsdb[fid]'";
  $rs=$db->excu($sqlsel);
  if ($db->num_rows($rs)<=0){
    $fun->popmassage("非法操作，系统将自动返回上一页!","","popback");
    exit();
  }
  else{
    $nei_classdb=$db->fetch_array($rs);
  }
  
  if($nei_classdb['classtype'] == 4){?>
	<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><?php echo $article_title;?></title>
<meta name="searchtitle" content="<?php echo $web_title2.$webdb['metakeywords'];?>">
<meta name="description" content="<?php echo $web_title2.$webdb['webdsc'];?>">
<meta name="keywords" content="<?php echo $web_title2.$webdb['metakeywords'];?>">
<link href="/images/style.css" type="text/css" rel="stylesheet">
<link href="/images/Page.css" type="text/css" rel="stylesheet">
<link href="/images/public.css" type="text/css" rel="stylesheet">
</head>
<script type="text/javascript" src="/js/jquery_min.js"></script>
<script type="text/javascript" src="/images/MobileSlide.js"></script>
<script type="text/javascript" src="/images/js.js"></script>
<script type="text/javascript" src="/images/index.js"></script>
<script type="text/javascript" src="/images/FootMenu.js"></script>
<script type="text/javascript" src="/images/Prlist.js"></script>
<style type="text/css">
div{margin:0px;padding:0px;}

#footer{background-color:white;color:white;width:100%;height:46px;position:fixed;bottom:0px;left:0px;}
#btm_foot{margin:10px auto 5px;margin-bottom:5px;position:fixe	d;bottom:0;border:1px solid #f00;width:50%;height:32px;text-align:center;font-size:16px;line-height:32px;background:#ff9900;border: 1px solid #ccc;display:block;-moz-border-radius: 3px; -webkit-border-radius: 3px;font-weight:bold;border-radius:5px;margin:0 auto; }
</style>

<body>
<div class="top_bg">
    <div class="TopMin320">
        <div class="top_title">
            商品详情</div>
        <div class="top_title_back PicIEPng">
            <a href="javascript:history.back();">
                <img src="/images/back_ico.png" /></a></div>
        <div class="top_title_home">
            <ul>
                <li class="PicIEPng" style="margin-right:30px;"><a style="color: #FFFFFF;font-size: 14px;height: 45px;" href="/gouwuche.php">购物车</a></li>
                <li class="PicIEPng"><a href="/">
                    <img src="/images/home_ico.png" /></a></li>
            </ul>
        </div>
    </div>
</div>

<div class="pr_show">
        <div class="banner">
            <ul id="BanCont">
                <li><img src="<?php echo get_photourl($newsdb["picurl"]);?>" width="298" height="298" /></li>         
			</ul>
            <ul class="banner_link">
            </ul>
        </div>
</div>

<div class="widthMAX pr_show_txt">       
        <p><?php echo $newsdb["title"];?></p> 
        <p id="pMarketPrice">
            <del>市场价￥<?php echo $newsdb["price"];?></del></p>
        <p id="pSalePrice">
            会员价：<span>￥<?php echo $newsdb["vipprice"];?></span></p>
</div>
	 <form name="buyform" id="buyform" method="post"  action="buybook.php">
	<div class="pr_show_kuang MarginTop10">
        <ul style="text-align:center;">
            <input id="hdGoods" name="price" value="<?php echo $newsdb["vipprice"];?>" type="hidden"/>
            <input id="hdGoodsEntitys" name="id"  value="<?php echo $id; ?>" type="hidden"  />
            <input id="ProductName" type="hidden" value="<?php echo $newsdb['title']; ?>" />
            <input id="ProductPicUrl" type="hidden" value="<?php echo get_photourl($newsdb["picurl"]); ?>" />
            <input id="articleshowId" type="hidden" value="<?php echo $newsdb["id"]; ?>" />
            <input id="ProductId" type="hidden" value="<?php echo $id; ?>" />
            <li><span>数量：</span>
                <img class="minus" src="/images/minus.jpg" />
                <input id="txtCount" name="buynum" type="text" value="1" maxlength="5" onKeyUp="value=value.replace(/[^\d]/g,'')"
                    onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
                    class="KingMum" />
                <img class="Plus" src="/images/Plus.jpg" />
                <span id="spInventory" class="Maximum">99</span> </li>
        </ul>
        <div class="pr_show_btn" style="text-align:center;">
			    <!-- <a id="aFavorites" href="javascript:void(0);" title="加入购物车" class="btn_favorite" > </a><a id="aAddShoppingCart" href="javascript:void(0);" onclick="nowbuy(this);" title="立即购买" class="btn_shop"> -->
			    <a id="aFavorites" href="javascript:void(0);" onclick="addCart(this);" title="加入购物车" class="btn_favorite" > </a><a id="aAddShoppingCart" href="javascript:void(0);" onclick="nowbuy(this);" title="立即购买" class="btn_shop">
        </a>
        </div>
    </div>

	<div class="pr_show_kuang MarginTop10">
        <div class="widthMAX">
            <div class="FloatRight">
        </div>
        <div class="pr_show_aboutTxt"><?php 
	  if ($newsdb["flvurl"]!="" and $nei_classdb["isdown"]!=1){
	  $newsdb["flvurl"]=get_video($newsdb["flvurl"]);
	  echo "<p align=\"center\">".$newsdb["flvurl"]."</p>";
	  }
	  ?>

<?php echo str_replace("src=\"/upload_files/","src=\"/upload_files/",stripslashes($newsdb["content"]));?></div>
    </div>
</div>
	<div class="clear"></div>
	
<!--	<div style=" position:fixed;bottom:0;border:1px solid #f00;width:30%;height:36px;text-align:center;font-size:16px;line-height:36px;
background:#ff9900;border: 1px solid #ccc;display:block;-moz-border-radius: 5px; -webkit-border-radius: 5px; margin-left:13%;font-weight:bold;border-radius:10px; "><a id="aFavorites" href="javascript:void(0);" title="立即购买" onClick="document.buyform.submit()"><font color="#FFFFFF">立即购买</font></a></div>-->
<!--<div style="height:30px;"></div>
<div style="position:fixed;bottom:0;background:#fff;width:100%;height:50px;line-height:50px;text-align:center;border:1px solid #fff;">
<div style="margin-top:10px;border:1px solid #f00;width:50%;font-size:16px;line-height:32px;background:#ff9900;border: 1px solid #ccc;-moz-border-radius: 3px; -webkit-border-radius: 3px;font-weight:bold;border-radius:5px; "><a href=""><font color="#FFFFFF">立即购买</font></a></div>
</div>-->
<?php $ishide_foot=1; require("w_foot.php");?>
<div id="footer">
<div id="btm_foot"><a href="javascript:void(0);" onclick="nowbuy(this);"><font color="#FFFFFF">立即购买</font></a></div>


	</form>
<script type="text/javascript">
	function addCart(that){
		var id = $("#ProductId").val();
		var price = $("#hdGoods").val();
		var count = $("#txtCount").val();
		var name = $("#ProductName").val();
		var picurl = $("#ProductPicUrl").val();
		var aid = $("#articleshowId").val();
		$.post('#',{'type':'cart','id':id,'count':count,'price':price,'name':name,'picurl':picurl,'aid':aid},function(data){
			if (data.success == true) {
				alert(data.msg);
				return;
			} else {
				alert(data.msg);
			}
		},'json');
	}
	  
	function nowbuy(that){
		var id = $("#ProductId").val();
		var price = $("#hdGoods").val();
		var count = $("#txtCount").val();
		var all = price*count;
		var str = "你确定立即消费 ￥"+all+" 购买"+count+"件商品吗？";
		if(confirm(str)){
			$.post('#',{'type':'nowbuy','id':id,'count':count},function(data){
				if (data.success == true) {
					alert(data.msg);
					setTimeout('window.location.href=location.href',1000);
					return;
				} else {
					alert(data.msg);
				}
			},'json');
		}
	}
</script>
<?php }else{
  	
  $fupid=$db->get_f_aid($nei_classdb["fid"]);
//  $web_title="$nei_classdb[name]";
//  $web_title2="$nei_classdb[name]";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><?php echo $article_title;?></title>
<meta name="searchtitle" content="<?php echo $web_title2.$webdb['metakeywords'];?>">
<meta name="description" content="<?php echo $web_title2.$webdb['webdsc'];?>">
<meta name="keywords" content="<?php echo $web_title2.$webdb['metakeywords'];?>">
<link href="images/style.css" rel="stylesheet" type="text/css" />
</head>
<script language="javascript" src="js/jquery_min.js"></script>
<body>
<?php
$head_hide=1;
require("w_head.php");
?>
<div id="news_con">
	<div class="t1"><?php echo $newsdb["title"];?></div>
	<div class="t2">
	<?php
	echo "时间：".date("Y-m-d ",strtotime($newsdb["posttime"]));
	?>
	<a href="weixin://contacts/profile/jinanyf" style="color:#FF0000;">关注<?php echo $webdb["vpp_jigoucode"]?></a>
	<?php
	if (trim($newsdb["author"])!=""){
		echo "&nbsp;&nbsp;".$newsdb["author"];
	}
//	else{
//		echo "&nbsp;&nbsp;".$webdb["vpp_jigoucode"];
//	}
	echo "&nbsp;&nbsp;阅读：".$newsdb["hits"]."次";
	?>
	</div>
	<div class="t3">
	  <?php 
	  if ($newsdb["flvurl"]!="" and $nei_classdb["isdown"]!=1){
	  $newsdb["flvurl"]=get_video($newsdb["flvurl"]);
	  echo "<p align=\"center\">".$newsdb["flvurl"]."</p>";
	  }
	  ?>

<?php echo str_replace("src=\"/upload_files/","src=\"http://".$_SERVER['HTTP_HOST']."/upload_files/",stripslashes($newsdb["content"]));?></div>
	</div>
	<div class="clear"></div>
</div>
<?php
if ($fupid==24){
?>
<div class="more" id="pagemore"><a href="ph.php">阅读排行榜</a></div>
<div class="more" id="pagemore" style="margin-top:10px;"><a href="ph.php?actions=new">最新微分享</a></div>
<?php
}

$rs=$db->excu("select * from mx_vpp_article where fid='$newsdb[fid]' and yz='1' and aid<>'$newsdb[aid]' order by isgood desc,istop desc, orderid, posttime desc, aid desc limit 10");
if ($db->num_rows($rs)>0){
?>
<div id="newsot">
	<h1><img src="images/news_1.png" /><span>最新更新</span></h1>
	<ul>
		<?php 
		while ($rsdb=$db->fetch_array($rs)){
		?>
		<li><a href="articleshow.php?id=<?php echo $rsdb["aid"]?>&fromwxopenid=<?php echo $wxmxopenid;?>"><?php echo $rsdb["title"]?></a></li>
		<?php
		}
		?>
	</ul>
</div>

<?php
}
$newsdb["title"]=str_replace("（","(",$newsdb["title"]);
$newsdb["title"]=str_replace("）",")",$newsdb["title"]);
$newsdb["description"]=str_replace("（","(",$newsdb["description"]);
$newsdb["description"]=str_replace("）",")",$newsdb["description"]);
?>
<script>
//弹出框中图片的切换
(function() {
var imgs = jQuery(".t3 img"),
imgsSrc = [],
minWidth = 0;
imgs.each(function() {
var jqthis = jQuery(this),
src = jqthis.attr('data-src') || jqthis.attr('src');
if (jqthis.width() >= minWidth && src && typeof(jqthis.parent().attr("href"))== "undefined") {
imgsSrc.push(src);
jqthis.on('click', function() {
reviewImage(src);
});
}
});

function reviewImage(src) {
if (typeof window.WeixinJSBridge != 'undefined') {
WeixinJSBridge.invoke('imagePreview', {
'current' : src,
'urls' : imgsSrc
});
}
}
    })();
</script>
<?php require("w_foot.php");}?>